/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2021-07-15     MBW       the first version
 */
#ifndef sensor_JY901B_931_H_
#define sensor_JY901B_931_H_
#include <rtthread.h>
#include "sys.h"

#define DEG2RAD     0.017453293f    /* 度转弧度 π/180 */
#define RAD2DEG     57.29578f       /* 弧度转度 180/π */


#define SAVE            0x00
#define CALSW       0x01
#define RSW             0x02
#define RRATE           0x03
#define BAUD            0x04
#define AXOFFSET    0x05
#define AYOFFSET    0x06
#define AZOFFSET    0x07
#define GXOFFSET    0x08
#define GYOFFSET    0x09
#define GZOFFSET    0x0a
#define HXOFFSET    0x0b
#define HYOFFSET    0x0c
#define HZOFFSET    0x0d
#define D0MODE      0x0e
#define D1MODE      0x0f
#define D2MODE      0x10
#define D3MODE      0x11
#define D0PWMH      0x12
#define D1PWMH      0x13
#define D2PWMH      0x14
#define D3PWMH      0x15
#define D0PWMT      0x16
#define D1PWMT      0x17
#define D2PWMT      0x18
#define D3PWMT      0x19
#define IICADDR     0x1a
#define LEDOFF      0x1b
#define GPSBAUD     0x1c

#define YYMM                0x30
#define DDHH                0x31
#define MMSS                0x32
#define MS                  0x33
#define AX                  0x34
#define AY                  0x35
#define AZ                  0x36
#define GX                  0x37
#define GY                  0x38
#define GZ                  0x39
#define HX                  0x3a
#define HY                  0x3b
#define HZ                  0x3c
#define Roll                0x3d
#define Pitch               0x3e
#define Yaw                 0x3f
#define TEMP                0x40
#define D0Status        0x41
#define D1Status        0x42
#define D2Status        0x43
#define D3Status        0x44
#define PressureL       0x45
#define PressureH       0x46
#define HeightL         0x47
#define HeightH         0x48
#define LonL                0x49
#define LonH                0x4a
#define LatL                0x4b
#define LatH                0x4c
#define GPSHeight   0x4d
#define GPSYAW      0x4e
#define GPSVL               0x4f
#define GPSVH               0x50
//#define q0          0x51
//#define q1          0x52
//#define q2          0x53
//#define q3          0x54

#define DIO_MODE_AIN 0
#define DIO_MODE_DIN 1
#define DIO_MODE_DOH 2
#define DIO_MODE_DOL 3
#define DIO_MODE_DOPWM 4
#define DIO_MODE_GPS 5

struct STime
{
    unsigned char ucYear;
    unsigned char ucMonth;
    unsigned char ucDay;
    unsigned char ucHour;
    unsigned char ucMinute;
    unsigned char ucSecond;
    unsigned short usMiliSecond;
};
struct SAcc
{
    short a[3];
    short T;
};
struct SGyro
{
    short w[3];
    short T;
};
struct SAngle
{
    short Angle[3];
    short T;
};
struct SMag
{
    short h[3];
    short T;
};

struct SDStatus
{
    short sDStatus[4];
};

struct SPress
{
    long lPressure;
    long lAltitude;
};

struct SLonLat
{
    long lLon;
    long lLat;
};

struct SGPSV
{
    short sGPSHeight;
    short sGPSYaw;
    long lGPSVelocity;
};
struct SQ
{ short q[4];
};


typedef struct
{
    float q0;
    float q1;
    float q2;
    float q3;

}F_q0123;
typedef struct
{
    F_XYZ aac;
    F_XYZ gyro;
    F_XYZ gyro_ori;
    F_XYZ angel;
    F_XYZ dis;
    F_q0123 quaternion;
    float height;
    float press;
    unsigned int deta_ms;
    unsigned int freq;
    unsigned char show;
    float Vl53l0Dis;
    float QMC5883;
    float gpsHeight,GPSYaw,GPSV,Longitude,LongitudeDeg,Lattitude , LattitudeDeg ;
    unsigned int ucYear , ucMonth , ucDay , ucHour , ucMinute , ucSecond ;
}JY_Sensor;
typedef struct
{
    F_XYZ aac;
    F_XYZ vel;
    F_XYZ pos;
    float flow_vx , flow_vy;
    float gyrox , gyroy , gyroz;
    unsigned int deta_ms;
    unsigned int freq;
    unsigned char show;//匿名数据显示开关
    float Velz_KF_Q;
    float Velz_KF_R;
}nav_data;
typedef struct
{
    float ConTask_freq;
    float ConTask_ms;
    float SenProTask_freq;
    float SenProTask_ms;
    float Us016Task_freq;
    float Us016Task_ms;
    float NimingTask_freq;
    float NimingTask_ms;
    float testTask1_freq;
    float testTask2_freq;

}task_time;
typedef struct
{
    float DCM[3][3];        //机体坐标系 -> 地理坐标系
    float DCM_T[3][3];      //地理坐标系 -> 机体坐标系
}_Matrix;
extern JY_Sensor JY901_data;
extern _Matrix Mat;
extern struct STime        stcTime;
extern struct SAcc         stcAcc;
extern struct SGyro        stcGyro;
extern struct SAngle   stcAngle;
extern struct SMag         stcMag;
extern struct SDStatus stcDStatus;
extern struct SPress   stcPress;
extern struct SLonLat  stcLonLat;
extern struct SGPSV        stcGPSV;
extern struct SQ       stcQ;
rt_err_t uart_input(rt_device_t dev, rt_size_t size);
void get_JY901B(void);
void init_JY931_901B(void);
void get_JY_data_task(void *p);
#endif /* 传感器_JY901B_931_H_ */
